<template>
    <el-dialog
      :title="title"
      :before-close="handleClose"
      :visible="justInput"
      :width="handleScreenWidthToVw(350)+'px'"
      v-loading="dialogLoading"
    >
        <el-form  ref="form" :rules="rules"  :model="form" :label-width="handleScreenWidthToVw(100)+'px'" >
            <el-form-item v-if="title === '入园时间'" :label="title" prop="registerDate">
                <el-date-picker
                    v-model="form.inputDate"
                    type="date"
                    placeholder="选择日期"
                    format="yyyy-MM-dd"
                    value-format="timestamp"
                    clearable>
                </el-date-picker>
            </el-form-item>
            <el-form-item  v-if="title === '离园时间'" :label="title" prop="registerDate">
                <el-date-picker
                    v-model="form.outDate"
                    type="date"
                    placeholder="选择日期"
                    format="yyyy-MM-dd"
                    value-format="timestamp"
                    clearable>
                </el-date-picker>
            </el-form-item>
              <el-form-item v-else :label="title" prop="parkState">
                <el-select v-model="form.parkState"  clearable filterable class="w-100P">
                <el-option
                    v-for="state in netTypeList"
                    :key="state.value"
                    :value="state.value"
                    :label="state.label"
                />
                </el-select>
            </el-form-item>
              <el-form-item>
                    <el-button size="mini" type="primary" @click="success('form')">保存</el-button>
                    <el-button size="mini" @click="handleClose()">取消</el-button>
                </el-form-item>
        </el-form>
    </el-dialog>
</template>
<script>
import { handleScreenWidthToVw } from '@/utils/tools'
import { ApiEnterpriseInfo,UpdateEnterprise } from '../api'

export default {
      props: {
        title: { type: String, default: '入园日期' },
        justInput: { type: Boolean, default: false },
        justId: { type: Number, default: 0}
    },
    data() {
        return {
               netTypeList:[
                {value:1,label:'在园'},
                {value:0,label:'离园'}
            ],
            dialogLoading:true,
            form:{},
            rules: {
                registerDate: [
                    { required: true, message: '请选择日期', trigger: 'blur' }
                ],
                parkState: [
                    { required: true, message: '请选择在园状态', trigger: 'blur' }
                ],
             

            }
        }
    },
    computed: {
    handleScreenWidthToVw() {
        return handleScreenWidthToVw
    },
},
methods: {
    success(form){
        this.$refs[form].validate((valid) => {
            if (valid) {
                UpdateEnterprise({customerList:this.form}).then(res => {
                if(res) {
                  this.$message({
                    message: '修改成功！',
                    type: 'success'
                  })
                }
              })
                this.$emit('dateDialog')
            } else {
            return false;
            }
        });
    },
    getIdInfo(id) {
        ApiEnterpriseInfo({enterpriseId:id}).then(res => {
            this.form = res
            this.dialogLoading = false
        })
    },
    handleClose() {
        this.$emit('dateDialog')
        },
    }
}
</script>
<style scoped>
::v-deep .el-dialog{
    border-radius: 5px;
}
</style>
